<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "grp_city".
 *
 * @property integer $id
 * @property string $name
 */
class GrpCity extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'grp_city';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name'], 'string', 'max' => 24],
            [['search_index'], 'match', 'pattern' => '/^[A-Z]{1,2}$/'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
        ];
    }
    
    //省份
    public static function province()
    {
        return self::find()->where(['like','id','__0000',false])->asArray()->all();
    }
    //城市
    public static function city($province_id)
    
    {
        return self::find()->where(['like','id',intval($province_id/10000).'__00',false])->andWhere(['<>','id',$province_id])->asArray()->all();
    }
    //区域
    public static function area($city_id)
    {
        //直辖市 
        return self::find()->where(['like','id',intval($city_id/100).'%',false])->asArray()->all();
    }
    //直辖市区
    public static function area2($province_id)
    {
        return self::find()->where(['like','id',intval($province_id/10000).'%',false])->andWhere(['<>','id',$province_id])->asArray()->all();
    }
    //直辖市不选区
    public static function area3($province_id)
    {
        return self::find()->where(['id'=>$province_id])->asArray()->all();
    }
    
    
}
